package com.blen.videolib;

import android.app.Activity;
import android.content.DialogInterface;
import android.text.TextUtils;


/**
 * Created by zhaoshuang on 17/2/23.
 */

public abstract class BaseActivity extends Activity {

    private ProgressDialog progressDialog;


    public boolean isProgressShowing(){
        return progressDialog!=null && progressDialog.isShowing();
    }

    public void showProgress(){
        showProgress(null);
    }

    public void showProgress(String msg) {
        showProgress(msg,null);
    }

    public void showProgress(String msg, DialogInterface.OnCancelListener listener){
        if (progressDialog == null) {
            if(TextUtils.isEmpty(msg)){
                msg = "视频处理中";
            }
            progressDialog = new ProgressDialog(this, msg);
            if(listener!=null) {
                progressDialog.setOnCancelListener(listener);
            }
        }
        progressDialog.show();
    }

    public void hideProgress() {
        try {
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        } catch (Exception e) {
            e.printStackTrace();
            progressDialog = null;
        }
    }

    public void setProgressText(String txt){
        if(progressDialog!=null&& progressDialog.isShowing()){
            progressDialog.setMsg(txt);
        }
    }

}
